package DAO;

import Exceptions.DaoException;
import Interfaces.IDeleteUser_Dao;
import Models.DeleteUser;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DeleteUser_Dao implements IDeleteUser_Dao {

    @Override
    public DeleteUser ValidateDelete(String username, String pass) throws DaoException {
        DeleteUser r = new DeleteUser();
        Connection conn = null;
        PreparedStatement pst = null;

        try {
            conn = DAO.javaconnect.ConnecrDb("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/nlr");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DeleteUser_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            Statement stmt = conn.createStatement();
            String query1 = "delete  from user where username=? and pass=?";
            stmt.execute(query1);
            ResultSet rs = stmt.executeQuery("SELECT * FROM user");
            while (rs.next()) {
                r.setUsername(rs.getString("name"));
                r.setPass(rs.getString("pass"));
            }

        } catch (SQLException ex) {
            Logger.getLogger(DeleteUser_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }

        return r;

    }

}
